<template>
    <div class="info-content">
        <div class="info-header">
            <div class="w1200">
                <div class="info-title">新闻中心</div>
                <div>了解绿通云最新资讯</div>
            </div>
        </div>
        <div class="consult-info">
            <div class="w1200">
                <div class="consult-title">{{ articleInfo?.title || '' }}</div>
                <div class="consult-card">
                    <div class="consult-content">
                        <img src="https://image.lutongjiakao.com/system/b35c7c10be674c52ac8e5517083adfb7.png" alt=""
                            class="icon-img">
                        <div class="consult-time">{{ articleInfo?.publishTime || '' }}</div>
                    </div>
                </div>
                <div v-html="articleInfo?.content" class="article-content"></div>
                <div class="label">
                    标签：
                </div>
                <div class="label-content">
                    <div
                        class="labelItem"
                        v-for="(item, index) in (articleInfo?.label ? articleInfo.label.split(',') : [])"
                        :key="index"
                    >
                        {{ item }}
                    </div>
                </div>
            </div>
        </div>
    </div>
</template>
<script lang="ts" setup>
import { ref, onMounted, watch } from 'vue'
import { getArticleInfo } from '@/api/index'
import { useRoute } from 'vue-router'

const route = useRoute()
const id = ref(route.query.id)

const articleInfo = ref<any>(null)

const fetchArticleInfo = async () => {
    if (!id.value) return
    const res = await getArticleInfo({ id: id.value })
    if (res.code === '0') {
        articleInfo.value = res.data
    }
}

// 监听路由参数变化
watch(() => route.query.id, (newId) => {
    id.value = newId
    fetchArticleInfo()
}, { immediate: true })

onMounted(() => {
    fetchArticleInfo()
})
</script>
<style lang="scss" scoped>
@use 'sass:math';

@function rem($px) {
    @return math.div($px, 16) * 1rem;
}

.w1200 {
    width: rem(900);
    margin: 0 auto;
}

.info-header {
    height: rem(360);
    padding-top: rem(50);
    background: url('https://image.lutongjiakao.com/system/fef61bd2f7114d0f88a80fb20fb789a4.png') no-repeat 50% / cover;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.info-title {
    font-size: rem(36);
    color: #000;
    font-weight: bold;
    margin-bottom: rem(10);
}

.consult-info {
    padding: rem(40);
}

.consult-title {
    color: #000;
    font-size: rem(18);
    font-weight: bold;
    margin-bottom: rem(10);
}

.consult-card {
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

.consult-content {
    display: flex;
    align-items: center;
    overflow: hidden;
    -webkit-box-orient: vertical;
    word-break: break-all;
    line-height: 1;
}

.icon-img {
    width: rem(9);
    height: rem(9);
    margin-right: rem(5);
}

.consult-time {
    color: #999;
    font-size: rem(10);
    margin-right: rem(5);
}

.label {
    margin-top: rem(30);
    font-size: rem(11);
    margin-bottom: 20px;
}

.label-content {
    display: flex;
}

.labelItem {
    margin-right: rem(10);
    padding: rem(2) rem(15);
    font-size: rem(12);
    color: #666;
    background: #f3f6f7;
    border-radius: rem(2);
    cursor: pointer;

    &:hover {
        background-color: #0abc54;
        color: #fff;
    }
}

.article-content {
    margin: rem(20) 0;
}
</style>